package guiTest;

public class Duration implements Comparable<Duration> 
{
	int durationVal;
	int durationInSeconds;
	String durationString;
	
	public Duration(int duration)
	{
		setDuration(duration);		
	}

	@Override
	public int compareTo(Duration o)
	{
		int durationToCompare = o.getDurationVal(); 

		if(durationVal < durationToCompare)
		{
			return -1;
		}
		
		if(durationVal > durationToCompare)
		{
			return 1;
		}
		
		return 0;
	}
	
	public void setDuration(int newDuration)
	{
		durationVal = newDuration;
		durationString = convertToString(durationVal);
		
		double totalSeconds = (1.0 * durationVal) / 1000.0;
		int total = (int)totalSeconds;
		durationInSeconds = total;
	}
	
	public int getDurationVal()
	{
		return durationVal;
	}
	
	public int getDurationInSeconds()
	{
		return durationInSeconds;
	}
	
	public static String convertToString(int durationVal) 
	{
		double totalSeconds = (1.0 * durationVal) / 1000.0;
		int total = (int)totalSeconds;
		int minutes = total / 60;
		int seconds = (total % 60);
		
		return minutes + ":" + getSecondsString(seconds);
	}
	
	public static String getSecondsString(int k)
	{
		if(k < 10)
		{
			return "0" + k;
		}
		
		return "" + k;
	}
	
	@Override
	public String toString()
	{
		return durationString;
	}
}
